#!/usr/bin/ksh -x

dir1=$1
dir2=$2
if [ -d $dir1 -a -d $dir2 ];
 then 
 dir3=`date "+%Y-%m-%d"`
 dir4="$dir2/$dir3"
 mkdir $dir4
 echo "directory that is backuped $dir1 directory where backup is $dir2"\
 > $dir4/logfile.txt
 echo "directory for backup is $dir4" >> $dir4/logfile.txt
 else 
 echo "incorrect name of catalog" > $dir4/logfile.txt
fi
cd $dir1
for a in  `ls -1 $dir1`
do
if [ -d "$a" ];
then
TIME=`stat --printf %y $a | cut -f 1 -d ' '`  
echo "$a is directory start archiving">>$dir4/logfile.txt
tar -cjf $a.$TIME.tar $a 
mv $a.$TIME.tar "$dir4"
echo "move $a.$TIME.tar in $dir4 is complete" >> $dir4/logfile.txt
else
echo "$a is not directory" >> $dir4/logfile.txt 
fi
done 
